<?php
namespace Admin\Controller;
use Think\Controller;

class PublicController extends Controller
{
	// 登陆
	public function login()
	{
		if(IS_AJAX) {
			$verify = I('post.');
			$user = D('user');
			$trueDate = $user -> where("username = '$verify[username]' and userpass = "."'".md5($verify['userpass'])."'") -> find();
			if($trueDate) {
				session('admin.username', $verify['username']);
				session('admin.islogin','1');
				$this -> ajaxReturn(array('msg' => '登陆成功！','url' => '/admin/product/index', 'status' => '0'));
			}else{
				$this -> ajaxReturn(array('msg' => '用户名或验证码错误！', 'status' => '1'));
			}
		}else{
			$this -> display();
		}
	}
	// 登出！
	public function logout()
	{
		session(null);
		$this -> redirect('/admin/public/login');
	}
}